package com.ourygo.fileselect.base

import android.content.pm.ActivityInfo
import android.content.res.Configuration
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.hjq.permissions.OnPermissionCallback
import com.hjq.permissions.XXPermissions
import com.ourygo.fileselect.util.Utils


open class BaseActivity : AppCompatActivity() {

    companion object {
        @JvmField
        var isHorizontal: Boolean = false
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setHorizontal()
    }

    protected fun setHorizontal() {
        //如果是竖屏才进行横屏，否则会旋转180°
        if (this.resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT) {
            if (isHorizontal) requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
        }
    }

    protected fun show(message: String) {
        Utils.show(message)
    }

    protected fun s(resId: Int): String {
        return Utils.s(this, resId)
    }

    protected fun requestPermissions(
        permissions: Array<String>,
        listener: OnPermissionCallback
    ) {
        XXPermissions.with(this)
            // 申请单个权限
            .permission(permissions)
            // 申请多个权限
            // 设置权限请求拦截器（局部设置）
            //.interceptor(new PermissionInterceptor())
            // 设置不触发错误检测机制（局部设置）
            //.unchecked()
            .request(listener);

    }

}
